package com.alks.function.mapper;

import com.alks.entity.data.entity.PcStitchWorkerRep;
import com.alks.entity.data.entity.PcStitchWorkerReq;
import com.alks.entity.data.entity.SdUser;
import com.alks.entity.data.entity.sys.SysUser;
import com.alks.function.data.dto.sys.SdUserDto;
import com.alks.function.data.request.sys.SdUserRequest;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.mapstruct.Mapper;

import java.util.List;
import java.util.Map;

@Mapper
public interface SdUserMapper extends BaseMapper<SdUser> {

    String getDeptNo(String user);

    List<PcStitchWorkerRep> workerList(PcStitchWorkerReq req);

    @Insert("INSERT INTO PC_STITCH_WORKER VALUES(#{companyId},#{line},#{workerId},#{workerName})")
    void insertIntoStitchWorker(PcStitchWorkerRep req);

    @Select("SELECT DISTINCT WORKER_ID FROM PC_STITCH_WORKER")
    List<String> getIds();

    Integer deleteStitchWorkersByIds(List<String> ids);

    @Select("SELECT DISTINCT WORKER_ID FROM PC_ORDER_PROD_STATUS WHERE WORKER_ID IS NOT NULL")
    List<String> getUseIds();

    Integer updateStitchWorker(@Param("ids") List<String> ids, @Param("line") String line);

    /*根据公司id和用户名查询部门*/
    @Select("SELECT DEPT_NO FROM SD_USER WHERE COMPANY_ID = #{companyId} AND USER_ID = #{loginName}")
    SdUser getDeptByCompanyIdAndName(@Param("companyId") String companyId, @Param("loginName") String loginName);

    @Select("SELECT * FROM SD_USER WHERE USER_ID = #{userId}")
    SdUser getUserByUserId(@Param("userId") String userId);

    /**
     * 查询用户信息
     * @param request
     * @param companyId
     * @return
     */
    List<SdUserDto> getUser(@Param("t") SdUserRequest request,@Param("companyId") String companyId);

    SdUser getUser3(String userId);

    /**
     * 根据id查询个人信息
     * @param userId
     * @param companyId
     * @return
     */
    SdUserDto getUser2(@Param("userId") String userId,@Param("companyId") String companyId);

    /**
     * 删除
     * @param userId
     */
    @Delete("delete from SD_USER where USER_ID=#{userId}")
    void delUser(String userId);

    /**
     * 查询是否被引用
     * @param posId
     * @return
     */
    @Select("select count(0) from SD_USER where POS_ID=#{posId} ")
    Integer getPosId(String posId);

    Integer getUserIdByName(String userName);

    Integer getUserIdByLogin(String loginName);

    Map<String,Object> getWorkName(String workId);

    SysUser selectUserWithRoleKey(@Param("userId") long userId, @Param("roleKey") String subcontractQcRole);

    void updatePassword(SdUser sdUser);
}
